<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" href="<%=basePath %>front/css/index.css">

</head>
<body style="background:url(../images/bg1.jpg) no-repeat;">
<jsp:include page="top.jsp"></jsp:include>
<div class="box-lottery" style="margin-top:200px;">
<font style="font-size:40px;color:#fff;float:left;">剩余<i id="drawNum">${USER.drawNum }</i>次</font>
<font style="font-size:40px;color:#fff;float:right;margin-right:-100px;">剩余<i id="integralNum">${USER.integralNum }</i>积分</font>
	<div class="lottery-wrap" style="transform: rotate(-45deg);" id="zhuanpan">
		<span class="lottery-span1" data-id="1">
			<i>京东卡<br>10元</i><img src="<%=basePath %>front/images/lottery_01.png" alt="京东卡10">
		</span>
		<span class="lottery-span2" data-id="2">
			<i>京东卡<br>20元</i><img src="<%=basePath %>front/images/lottery_02.png" alt="京东卡20">
		</span>
		<span class="lottery-span3" data-id="3">
			<i>京东卡<br>50元</i><img src="<%=basePath %>front/images/lottery_03.png" alt="京东卡50">
		</span>
		<span class="lottery-span4" data-id="4">
			<i>京东卡<br>100元</i><img src="<%=basePath %>front/images/lottery_04.png" alt="京东卡100">
		</span>
		<span class="lottery-span5" data-id="5">
			<i>谢谢参与</i><img src="<%=basePath %>front/images/lottery_05.png" alt="谢谢参与">
		</span>
		<span class="lottery-span6" data-id="6">
			<i>京东卡<br>200元</i><img src="<%=basePath %>front/images/lottery_06.png" alt="京东卡200">
		</span>
		<span class="lottery-span7" data-id="7">
			<i>京东卡<br>500元</i><img src="<%=basePath %>front/images/lottery_07.png" alt="京东卡500">
		</span>
		<span class="lottery-span8" data-id="8">
			<i>iQOO Pro<br>手机</i><img src="<%=basePath %>front/images/lottery_08.png" alt="iQOO Pro">
		</span>
	</div>
	<a class="lottery-btn" href="javascript:void(0);"><i></i>立即抽奖</a>
</div>

<script src="<%=basePath %>front/js/jquery.min.js"></script>
<script src="<%=basePath %>front/js/lib/anime.min.js"></script>
<script src="<%=basePath %>front/js/app/lottery.js"></script>
<script>
	var Lottery = Turntable.create();
	$('.lottery-btn').on('click', function(){
		
		
		
		var a = parseInt(document.getElementById("1").value);
		var b = a+parseInt(document.getElementById("2").value);
		var c = b+parseInt(document.getElementById("3").value);
		var d = c+parseInt(document.getElementById("4").value);
		var e = d+parseInt(document.getElementById("5").value);
		var f = e+parseInt(document.getElementById("6").value);
		var g = f+parseInt(document.getElementById("7").value);
		var h = g+parseInt(document.getElementById("8").value);
		a=a*100/h;
		b=b*100/h;
		c=c*100/h;
		d=d*100/h;
		e=e*100/h;
		f=f*100/h;
		g=g*100/h;
		h=h*100/h;
		var rand=Math.random() * 100;
		
		if(rand<a){
    		var num=0;
    	}else if(rand<b){
        	var num=1;
    	}else if(rand<c){
        	var num=2;
    	}else if(rand<d){
        	var num=3;
    	}else if(rand<e){
        	var num=4;
    	}else if(rand<f){
        	var num=5;
    	}else if(rand<g){
        	var num=6;
    	}else if(rand<h){
        	var num=7;
    	}
		var integralNum = "";
		var drawNum="";
		
		
		$.ajax( {
			url:'<%=basePath%>puser/subtract2',
			async: false,
			type:'post',
			data: {
				
			},
			datatype : "text",//"xml", "html", "script", "json", "jsonp", "text".           
			success : function(data) {
				drawNum=parseInt(data);
				
			},
			error : function() {
                alert("异常！！！");
                
            }
	});
		$.ajax( {
		url:'<%=basePath%>puser/subtract3',
		async: false,
		type:'post',
		data: {
			
		},
		datatype : "text",//"xml", "html", "script", "json", "jsonp", "text".           
		success : function(data) {
			integralNum=parseInt(data);
		},
		error : function() {
            alert("异常！！！");
            
        }
});
		
    	//3 ->5  京东卡100
    	//2 ->6  京东卡50
    	//1 ->7  京东卡20
    	//4 ->1  谢谢参与
    	//5 ->4  京东卡200
    	//6 ->3  京东卡500
    	//7 ->2  iQOO Pro
    	//8 ->8  京东卡10
		if(drawNum===0){
				alert("次数用完了！！");
			}else if(integralNum<10){
				alert("积分不足！");
			}else{
				var drawnum = document.getElementById("drawNum");
				drawnum.innerHTML='';
				var integralnum = document.getElementById("integralNum");
				drawnum.innerHTML='';
				integralnum.innerHTML='';
				$.ajax( {
					url:'<%=basePath%>puser/subtract',
					async: false,
					type:'post',
					data: {
						
					},
					datatype : "text",//"xml", "html", "script", "json", "jsonp", "text".           
					success : function(data) {
						$("#drawNum").append(data);
					},
					error : function() {
		                alert("异常！！！");
		                
		            }
			});
				$.ajax( {
					url:'<%=basePath%>puser/subtract3',
					async: false,
					type:'post',
					data: {
						
					},
					datatype : "text",//"xml", "html", "script", "json", "jsonp", "text".           
					success : function(data) {
						$("#integralNum").append(data);
						
					},
					error : function() {
			            alert("异常！！！");
			            
			        }
			});
				var id = num+1;
				
				$.ajax( {
					url:'<%=basePath %>myprize/addMyprize',
					async: false,
					type:'post',
					data: {
						id:id
					},
					datatype : "text",//"xml", "html", "script", "json", "jsonp", "text".           
					success : function(data) {
						
					},
					error : function() {
			            alert("添加我的奖品异常！！！");
			            
			        }
			});
				
			Lottery.start(num, function(index){

			alert("恭喜你获得："+$('span').eq(index+1).find('i').text());
			console.log('index', index, 'lottery-span', 'lottery-span'+(index+1));
			
			
			
		});
			}
		
	});
	$(document).ready(function(){
		showAll();
	});
		function showAll(){
			debugger;
			
			var l = document.getElementById("zhuanpan");
			l.innerHTML='';
			$.ajax( {
							url:'<%=basePath%>prize/findAll',
							async: false,
							type:'post',
							data: {
								
							},
							datatype : "json",//"xml", "html", "script", "json", "jsonp", "text".           
							success : function(data) {
								var json=eval('(' + data + ')');
								$.each(json, function (n, item) {
									
									addGift(n,item);
								});
							},
							error : function() {
				                alert("异常！！！");
				                selAllFriend();	
				            }
					});
		}
		function addGift(n,item){
			var val = "<span class=\"lottery-span"+(n+1)+"\" data-id=\""+(n+1)+"\">"+
			"<i>"+item.name+"</i><img src=\"../../"+item.picpath+"\" alt=\"\">"+
			"</span><input type=\"hidden\" id=\""+(n+1)+"\" value=\""+item.probability+"\">";

			$("#zhuanpan").append(val);
		}
		
</script>

</body>
</html>